/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package View;

import java.io.Serializable;
import javax.faces.application.NavigationHandler;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.inject.Inject;
import javax.inject.Named;
import javax.servlet.http.HttpSession;
import org.apache.myfaces.extensions.cdi.core.api.scope.conversation.Conversation;
import org.apache.myfaces.extensions.cdi.core.api.scope.conversation.ConversationScoped;

/**
 *
 * @author carlos
 */
@Named
@ConversationScoped
public class SessionView implements Serializable {

  @Inject
  Conversation conversation;

  public void closeConversation(ActionEvent event) {
    conversation.close();
  }

  public String actionLogoff() {
    FacesContext fc = FacesContext.getCurrentInstance();
    ExternalContext ec = fc.getExternalContext();
    HttpSession session = (HttpSession) ec.getSession(false);
    session.invalidate();
    return "menu";
  }

  public void actionSelectRow(String action) {
    FacesContext ctx = FacesContext.getCurrentInstance();
    NavigationHandler nh = ctx.getApplication().getNavigationHandler();
    nh.handleNavigation(ctx, null, action);
  }
}
